%reload_ext pretty_jupyter
import os
import zipfile
import random
import numpy as np
import pandas as pd
import plotly_express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly.offline as pyo
import plotly.io as pio
import kaggle
from tqdm import tqdm
import cv2
import tensorflow as tf
import warnings
warnings.filterwarnings('ignore')
pyo.init_notebook_mode()
Data Description¶
Visualization assignment will be performed on the earthquake data from the past.
- Region: Worldwide
- Magnitude: 5.5+
- Start date: 1990-01-01
- End date: 2022-09-30
For the data visualisation assignment I want to investigate and try two new technologies:
- Plotly library for better visualisation and animation;
- Pretty Jupyter library to generate pretty HTML code out of Jupyter notebooks.
df = pd.read_csv("data/1990-01-01_mag-6.csv")
df = df.sort_values(by='time', ascending=True)
Overview of the data columns
| time | latitude | longitude | depth | mag | magType | nst | gap | dmin | rms | net | id | updated | place | type | horizontalError | depthError | magError | magNst | status | locationSource | magSource | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 16230 | 1990-01-02T01:25:06.560Z | 8.344 | 127.441 | 40.9 | 5.6 | mw | NaN | NaN | NaN | 1.1 | us | usp00043u7 | 2022-04-28T20:00:30.802Z | Philippine Islands region | earthquake | NaN | NaN | NaN | NaN | reviewed | us | hrv |
| 16229 | 1990-01-02T20:21:32.620Z | 13.408 | 144.439 | 135.8 | 5.8 | mw | NaN | NaN | NaN | 1.0 | us | usp00043v2 | 2022-04-28T20:00:37.654Z | 23 km W of Agat Village, Guam | earthquake | NaN | NaN | NaN | NaN | reviewed | us | hrv |
| 16228 | 1990-01-04T05:32:21.040Z | -15.397 | -172.850 | 53.5 | 6.5 | mw | NaN | NaN | NaN | 1.2 | us | usp00043wc | 2022-04-28T20:00:39.337Z | 118 km ENE of Hihifo, Tonga | earthquake | NaN | NaN | NaN | NaN | reviewed | us | hrv |
| 16227 | 1990-01-05T10:10:21.810Z | -8.800 | 106.442 | 29.0 | 5.8 | mw | NaN | NaN | NaN | 1.3 | us | usp00043xp | 2022-04-28T20:00:40.855Z | 200 km S of Pelabuhanratu, Indonesia | earthquake | NaN | NaN | NaN | NaN | reviewed | us | hrv |
| 16226 | 1990-01-05T13:03:44.300Z | -19.258 | -69.529 | 108.7 | 5.5 | mw | NaN | NaN | NaN | 1.2 | us | usp00043xw | 2016-11-09T21:36:19.079Z | 118 km SE of Arica, Chile | earthquake | NaN | 6.2 | NaN | NaN | reviewed | us | hrv |
# -.-|m {output: false}
df['date'] = pd.to_datetime(df['time']).dt.normalize()
df['month'] = pd.to_datetime(df['time']).dt.to_period('M')
df['year'] = pd.to_datetime(df['time']).dt.to_period('Y')
df.index = np.arange(1, len(df) + 1)
General Dataset Information¶
We begin with visualising average and maximum magnitude of the earthquakes over the years.
Maximum magnitude¶
df1 = df.groupby('year')['mag'].max()
fig = px.bar(df1, x=df1.index.to_timestamp(), y='mag')
fig.show()
Observations¶
- In the past years there were two earthquakes with magnitude of 9.1;
- It seems like there is certain seasonality in earthquakes power and onse in certain period a powerful earthquake happens.
Average magnitude¶
df1 = df.groupby('year')['mag'].mean()
fig = px.bar(df1, x=df1.index.to_timestamp(), y='mag')
fig.show()
Observations¶
- Over the years, mean values of the earthquakes are almost the same.
Earthquake progression over period¶
In the following section we would visualize all earthquakes over the different periods, to observe if there is any pattern in them happening.
Over years¶
px.set_mapbox_access_token("pk.eyJ1IjoiZnZhZmhhZSIsImEiOiJja3E5ZGhxaGowOGQxMm9ueXFqYXpzNG5mIn0.-u7PlWQhs-Tnpq87GLptcA")
fig = px.scatter_geo(df, lat="latitude", lon="longitude", color="mag",
animation_frame="year",
range_color=(min(df.mag), max(df.mag)), height=700)
fig.show()
Observations¶
- On the yearly plot it is clearly seen that all earthquakes heppen on the borders of tectonic plates;
- More than half of the earthquakes happen around the Pacific Plate.
Over months¶
px.set_mapbox_access_token("pk.eyJ1IjoiZnZhZmhhZSIsImEiOiJja3E5ZGhxaGowOGQxMm9ueXFqYXpzNG5mIn0.-u7PlWQhs-Tnpq87GLptcA")
fig = px.scatter_geo(df, lat="latitude", lon="longitude", color="mag",
animation_frame="month",
range_color=(min(df.mag), max(df.mag)), height=700)
fig.show()
Most powerful earthquakes¶
By plotting most powerful earthquakes, we try to understand whether they are concentrated in one area or not.
Interactive Map¶
df_globe = df.sort_values(by="mag", ascending=False).copy()[:100]
fig = go.Figure(data=go.Scattergeo(
lon = df_globe['longitude'],
lat = df_globe['latitude'],
text = [f'Magnitude: {mag} <br> Date: {date}' for mag, date in zip(df_globe['mag'], pd.to_datetime(df_globe['time']).dt.to_period("D"))],
mode = 'markers',
marker = dict(
size = 8,
opacity = 0.8,
autocolorscale = False,
colorscale = 'Reds',
symbol = 'diamond',
cmin = df_globe['mag'].min(),
color = df_globe['mag'],
cmax = df_globe['mag'].max(),
colorbar_title="Earthquake Magnitude <br> 7 Richter and up" )
)
)
fig.update_geos( projection_type="orthographic", landcolor="green", oceancolor="MidnightBlue", showocean=True, lakecolor="LightBlue" )
fig.update_layout( title = '100 most powerful earthquakes since the year 1990', xaxis_rangeslider_visible=True, height = 700 )
pio.show(fig)
Observations¶
- In the past years, Japan, Indonesia, Peru and Chile have received the most damage because of the most powerful earthquakes;
- There are no powerful earthquakes in Africa and Europe.
Table View¶
Please click to unfold the table.
keep = ['latitude', 'longitude', 'depth', 'mag', 'place']
df_globe = df.sort_values(by="mag", ascending=False).copy()[:100].drop(columns=[x for x in df_globe.columns if x not in keep])
df_globe.index = np.arange(1, len(df_globe) + 1)
Table
| latitude | longitude | depth | mag | place | |
|---|---|---|---|---|---|
| 1 | 38.2970 | 142.3730 | 29.00 | 9.10 | 2011 Great Tohoku Earthquake, Japan |
| 2 | 3.2950 | 95.9820 | 30.00 | 9.10 | 2004 Sumatra - Andaman Islands Earthquake |
| 3 | -36.1220 | -72.8980 | 22.90 | 8.80 | 36 km WNW of Quirihue, Chile |
| 4 | 2.0850 | 97.1080 | 30.00 | 8.60 | 78 km WSW of Singkil, Indonesia |
| 5 | 2.3270 | 93.0630 | 20.00 | 8.60 | off the west coast of northern Sumatra |
| 6 | -4.4380 | 101.3670 | 34.00 | 8.40 | 122 km SW of Bengkulu, Indonesia |
| 7 | -16.2650 | -73.6410 | 33.00 | 8.40 | 6 km SSW of Atico, Peru |
| 8 | 43.7730 | 147.3210 | 14.00 | 8.30 | 48 km E of Shikotan, Russia |
| 9 | 54.8920 | 153.2210 | 598.10 | 8.30 | Sea of Okhotsk |
| 10 | -31.5729 | -71.6744 | 22.44 | 8.30 | 48 km W of Illapel, Chile |
| 11 | 46.5920 | 153.2660 | 10.00 | 8.30 | Kuril Islands |
| 12 | 55.3635 | -157.8876 | 35.00 | 8.20 | 99 km SE of Perryville, Alaska |
| 13 | 0.8020 | 92.4630 | 25.10 | 8.20 | off the west coast of northern Sumatra |
| 14 | -18.1125 | -178.1530 | 600.00 | 8.20 | 267 km E of Levuka, Fiji |
| 15 | 15.0222 | -93.8993 | 47.39 | 8.20 | near the coast of Chiapas, Mexico |
| 16 | -13.8410 | -67.5530 | 631.30 | 8.20 | 55 km NNW of Reyes, Bolivia |
| 17 | -19.6097 | -70.7691 | 25.00 | 8.20 | 93 km NW of Iquique, Chile |
| 18 | 41.8150 | 143.9100 | 27.00 | 8.16 | 134 km SSW of Kushiro, Japan |
| 19 | -29.7228 | -177.2794 | 28.93 | 8.10 | Kermadec Islands, New Zealand |
| 20 | -49.3120 | 161.3450 | 10.00 | 8.10 | north of Macquarie Island |
| 21 | 46.2430 | 154.5240 | 10.00 | 8.10 | east of the Kuril Islands |
| 22 | -15.4890 | -172.0950 | 18.00 | 8.10 | 168 km SSW of Matavai, Samoa |
| 23 | -58.3753 | -25.2637 | 22.79 | 8.10 | South Sandwich Islands region |
| 24 | -62.8770 | 149.5270 | 10.00 | 8.10 | Balleny Islands region |
| 25 | -8.4660 | 157.0430 | 24.00 | 8.10 | 45 km SSE of Gizo, Solomon Islands |
| 26 | -0.8910 | 136.9520 | 33.00 | 8.09 | 101 km ENE of Biak, Indonesia |
| 27 | -23.3400 | -70.2940 | 45.60 | 8.00 | 36 km NNE of Antofagasta, Chile |
| 28 | -10.7990 | 165.1140 | 24.00 | 8.00 | 75 km W of Lata, Solomon Islands |
| 29 | -13.3860 | -76.6030 | 39.00 | 8.00 | 41 km SW of San Vicente de Cañete, Peru |
| 30 | -20.1870 | -174.1230 | 55.00 | 8.00 | 47 km SSE of Pangai, Tonga |
| 31 | -3.9800 | 152.1690 | 33.00 | 8.00 | 24 km N of Rabaul, Papua New Guinea |
| 32 | 19.0550 | -104.2050 | 33.00 | 8.00 | 5 km E of El Colomo, Mexico |
| 33 | -5.8119 | -75.2697 | 122.57 | 8.00 | 78 km NE of Navarro, Peru |
| 34 | 56.0039 | -149.1658 | 14.06 | 7.90 | 261 km SE of Chiniak, Alaska |
| 35 | 51.5640 | -177.6320 | 33.00 | 7.90 | 77 km WSW of Adak, Alaska |
| 36 | -6.2464 | 155.1718 | 135.00 | 7.90 | 35 km WNW of Panguna, Papua New Guinea |
| 37 | 36.2810 | 141.1110 | 42.60 | 7.90 | 47 km E of ?arai, Japan |
| 38 | 0.7290 | 119.9310 | 24.00 | 7.90 | 181 km N of Palu, Indonesia |
| 39 | -4.7210 | 102.0870 | 33.00 | 7.90 | 103 km S of Bengkulu, Indonesia |
| 40 | -4.5049 | 153.5216 | 94.54 | 7.90 | 140 km E of Kokopo, Papua New Guinea |
| 41 | -2.6250 | 100.8410 | 35.00 | 7.90 | 87 km SW of Sungai Penuh, Indonesia |
| 42 | 51.8486 | 178.7352 | 109.00 | 7.90 | Rat Islands, Aleutian Islands, Alaska |
| 43 | -13.8020 | 97.4530 | 10.00 | 7.90 | South Indian Ocean |
| 44 | 63.5141 | -147.4529 | 4.20 | 7.90 | 75 km E of Cantwell, Alaska |
| 45 | -7.1370 | 122.5890 | 587.30 | 7.90 | 169 km NNE of Maumere, Indonesia |
| 46 | 31.0020 | 103.3220 | 19.00 | 7.90 | 58 km W of Tianpeng, China |
| 47 | -18.4743 | 179.3502 | 670.81 | 7.90 | 45 km S of Levuka, Fiji |
| 48 | 44.6630 | 149.3000 | 33.00 | 7.90 | 128 km ESE of Kuril’sk, Russia |
| 49 | 51.1460 | 178.6500 | 33.00 | 7.80 | Rat Islands, Aleutian Islands, Alaska |
| 50 | -3.4870 | 100.0820 | 20.10 | 7.80 | 215 km SW of Sungai Penuh, Indonesia |
| 51 | -22.1010 | -176.7720 | 167.30 | 7.80 | 192 km WSW of Haveluloto, Tonga |
| 52 | -5.4960 | 151.7810 | 33.00 | 7.80 | 138 km SSW of Kokopo, Papua New Guinea |
| 53 | 52.7880 | -132.1010 | 14.00 | 7.80 | 206 km SW of Prince Rupert, Canada |
| 54 | 28.2305 | 84.7314 | 8.22 | 7.80 | 67 km NNE of Bharatpur, Nepal |
| 55 | -42.7373 | 173.0540 | 15.11 | 7.80 | 53 km NNE of Amberley, New Zealand |
| 56 | 0.3819 | -79.9218 | 20.59 | 7.80 | 27 km SSE of Muisne, Ecuador |
| 57 | -8.4800 | 121.8960 | 27.70 | 7.80 | 37 km WNW of Maumere, Indonesia |
| 58 | -12.5170 | 166.3820 | 35.00 | 7.80 | 196 km NW of Sola, Vanuatu |
| 59 | -10.4770 | 112.8350 | 18.40 | 7.80 | 249 km SSW of Kencong, Indonesia |
| 60 | 35.9460 | 90.5410 | 10.00 | 7.80 | Southern Qinghai, China |
| 61 | 40.5250 | 143.4190 | 26.50 | 7.80 | off the east coast of Honshu, Japan |
| 62 | 27.8386 | 140.4931 | 664.00 | 7.80 | Bonin Islands, Japan region |
| 63 | -45.7620 | 166.5620 | 12.00 | 7.80 | 97 km WSW of Te Anau, New Zealand |
| 64 | -10.6812 | 161.3273 | 40.00 | 7.80 | 69 km WSW of Kirakira, Solomon Islands |
| 65 | -4.9521 | 94.3299 | 24.00 | 7.80 | southwest of Sumatra, Indonesia |
| 66 | -5.2330 | 153.1020 | 30.00 | 7.80 | 135 km SE of Kokopo, Papua New Guinea |
| 67 | 1.1860 | 122.8570 | 25.70 | 7.80 | 75 km NNW of Gorontalo, Indonesia |
| 68 | -19.9870 | -69.1970 | 115.60 | 7.80 | 102 km ENE of Iquique, Chile |
| 69 | 55.0715 | -158.5960 | 28.00 | 7.80 | 99 km SSE of Perryville, Alaska |
| 70 | 54.8410 | 162.0350 | 33.00 | 7.80 | 156 km S of Ust’-Kamchatsk Staryy, Russia |
| 71 | 2.3830 | 97.0480 | 31.00 | 7.80 | 75 km E of Sinabang, Indonesia |
| 72 | -25.9960 | -177.5140 | 152.50 | 7.80 | south of the Fiji Islands |
| 73 | 12.9820 | 144.8010 | 59.30 | 7.80 | 32 km S of Inarajan Village, Guam |
| 74 | -14.9930 | -75.6750 | 33.00 | 7.70 | 60 km SW of Changuillo, Peru |
| 75 | -60.2738 | -46.4011 | 10.00 | 7.70 | Scotia Sea |
| 76 | -23.0511 | 171.6566 | 10.00 | 7.70 | southeast of the Loyalty Islands |
| 77 | 42.8510 | 139.1970 | 16.70 | 7.70 | 107 km W of Iwanai, Japan |
| 78 | -9.2840 | 107.4190 | 20.00 | 7.70 | 226 km SSW of Singaparna, Indonesia |
| 79 | -22.2470 | -69.8900 | 40.00 | 7.70 | 36 km ESE of Tocopilla, Chile |
| 80 | 13.0490 | -88.6600 | 60.00 | 7.70 | 28 km SSW of Puerto El Triunfo, El Salvador |
| 81 | -13.0060 | 166.5100 | 45.00 | 7.70 | 148 km NW of Sola, Vanuatu |
| 82 | -0.4140 | 132.8850 | 17.00 | 7.70 | 140 km WNW of Manokwari, Indonesia |
| 83 | -2.0710 | 124.8910 | 33.00 | 7.70 | 264 km ESE of Luwuk, Indonesia |
| 84 | 19.4193 | -78.7560 | 14.86 | 7.70 | 123 km NNW of Lucea, Jamaica |
| 85 | 15.6790 | 121.1720 | 25.10 | 7.70 | 4 km E of Macapsing, Philippines |
| 86 | 26.9510 | 65.5009 | 15.00 | 7.70 | 113 km NW of Bela, Pakistan |
| 87 | 53.8820 | 152.8860 | 632.80 | 7.70 | Sea of Okhotsk |
| 88 | 23.7720 | 120.9820 | 33.00 | 7.70 | 21 km S of Puli, Taiwan |
| 89 | -21.6960 | -179.5130 | 580.00 | 7.70 | Fiji region |
| 90 | -23.0080 | 169.9000 | 20.20 | 7.70 | 249 km E of Vao, New Caledonia |
| 91 | -23.8840 | 178.4950 | 675.40 | 7.70 | south of the Fiji Islands |
| 92 | 49.8000 | 145.0640 | 583.20 | 7.70 | 156 km ENE of Poronaysk, Russia |
| 93 | 18.5429 | 145.5073 | 196.00 | 7.70 | Pagan region, Northern Mariana Islands |
| 94 | -12.5840 | 166.6760 | 33.00 | 7.70 | 171 km NNW of Sola, Vanuatu |
| 95 | -5.7990 | 154.1780 | 30.10 | 7.70 | 155 km WNW of Panguna, Papua New Guinea |
| 96 | 11.7420 | -87.3400 | 44.80 | 7.70 | 83 km SSW of Corinto, Nicaragua |
| 97 | 54.4434 | 168.8570 | 10.00 | 7.70 | Komandorskiye Ostrova, Russia region |
| 98 | 38.0580 | 144.5900 | 18.60 | 7.70 | 272 km ESE of Kamaishi, Japan |
| 99 | -20.5709 | -70.4931 | 22.40 | 7.70 | 53 km SW of Iquique, Chile |
| 100 | 23.4190 | 70.2320 | 16.00 | 7.70 | 17 km NW of Bhach?u, India |